const app = getApp()
const utils=require('../../common/utils.js');
// const SM4Utils = require('../../common/SM4Utils.js');

var flag = true;
var color=0;
Page({
  data:{
    // text:"这是一个页面",
    nbFrontColor: '#000000',
    loginBackgroundColor: '#ffffff',
    color: "window",
    loading: false,
    disabled:false,
    userId: '',
    passWord: ''
  },

  treg: function treg() {
    wx.navigateTo({
      url: "./../teacher/tregdit"
    });
  },
  ureg: function ureg() {
    wx.navigateTo({
      url: "./../ulogin/ulogin"
    });
  },
  userId: function userId(e) {
    this.setData({ userId: e.detail.value });
  },
  passWord: function passWord(e) {
    this.setData({ passWord: e.detail.value });
  },

  login:function(){
    var that = this;
    that.disabled = true;
    that.loading = false;
    that.setLoading();

    console.log("点击了文字");

    if (that.data.userId == "") {
      // wx.showModal({
      //   content: "用户名不能为空",
      //   showCancel: false,
      //   success: function (res) {
      //     if (res.confirm) {
      //       //点击确定按钮
      //     } else if (res.cancel) {
      //       //点击取消按钮
      //     }
      //   }
      // })
      wx.showToast({
 
        title: '用户名不能为空',
         
        icon: 'none',
         
        duration: 2000
         
        })
    } else if (that.data.passWord == "") {
      wx.showModal({
        content: "密码不能为空",
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            //点击确定按钮
          } else if (res.cancel) {
            //点击取消按钮
          }
        }
      })
    }else {
      this.data = {
        "userId": that.data.userId,
        "passWord": that.data.passWord
      };
      utils.request('/login/login.do','POST',this.data,'加载中');
      
      wx.switchTab({
      
        url: '../index/index'
        
      })  
    }
    that.loading = true;
    that.disabled = false;
    that.setLoading();
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数

    
    this.setData({
      loginTitle: '登录',
      loginLoading: true,
      loginFrontColor: '#ffffff',
      loginBackgroundColor: '#1296db',
    })


    wx.getLocation({
      type: 'wgs84',
      success (res) {
        const latitude = res.latitude
        const longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        console.log(latitude);
        console.log(longitude);
        console.log(speed);
        console.log(accuracy);
      }
     })
  },
  onReady:function(){
    // 页面渲染完成
    this.setData({
      loginLoading: false
    })
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  setDisabled: function (e) {
    this.setData({
      disabled: !this.disabled
    })
  },
  setLoading: function (e) {
    this.setData({
      loading: !this.loading
    })
  }
})

